import torch
import numpy as np

ff = open("housing.data").readlines()
data = []
for line in ff:
    data.append(line.split(" "))
data = np.array(data).astype(float)
print(data.shape)

Y = data[:,-1]
X = data[:, 0:-1]
X_train = X[0:496, ...]
Y_train = Y[0:496, ...]
X_test = X[496:, ...]
Y_test = Y[496:, ...]

class Net(torch.nn.Module):
    def __init__(self, n_feature, n_output):
        super(Net, self).__init__()
        self.fc1 = torch.nn.Linear(n_feature, 100)
        self.fc2 = torch.nn.Linear(100, n_output)

    def forward(self, x):
        out = self.fc1(x)
        out = torch.relu(out)
        out = self.fc2(out)
        return out


net = Net(n_feature=13, n_output=1)
net.load_state_dict(torch.load("housing.model"))

x_data = torch.tensor(X_test, dtype=torch.float)
y_data = torch.tensor(Y_test, dtype=torch.float)
prediction = net.forward(x_data)
prediction = torch.squeeze(prediction) #移除张量维度为1的轴

print(x_data)
print(y_data)
print(prediction)
